Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QL: Remove the unnecessary DateTimeFunction.dateTimeFormat() #68788

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

palesz
Copy link
Contributor

@palesz palesz commented Feb 9, 2021

Removes the DateTimeFunction.dateTimeFormat() and the
TranslatorHandler.dateTimeFormat() methods that were
called, but had no effect on the translated queries.

One of the examples, when this happens, is when one side of the
BinaryComparison is a function. The BinaryComparison at the
end turns into a ScriptQuery, but in the intermediate steps the
ExpressionTranslators try to translate it to a RangeQuery.

Follows #68783

…ranslations lazy

Removes the `DateTimeFunction.dateTimeFormat()` method that was
called, but had no effect on the translated queries.

This change also adds laziness, so translations don't execute unnecessarily.

Before the `ExpressionTranslators` did some unnecessary
`Expression` -> `Query` translations, where the result queries were thrown
away by later translations (by the `wrapFunctionQuery`).

One of the examples, when this happens, is when one side of the
`BinaryComparison` is a function. The `BinaryComparison` at the
end turns into a `ScriptQuery`, but in the intermediate steps the
`ExpressionTranslators` try to translate it to a `RangeQuery`.

Follows elastic#68783
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

if (field instanceof StDistance && q instanceof GeoDistanceQuery) {
return ExpressionTranslator.wrapIfNested(q, ((StDistance) field).left());
public Query wrapFunctionQuery(ScalarFunction sf, Expression field, Supplier<Query> querySupplier) {
if (field instanceof StDistance && querySupplier instanceof GeoDistanceQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be: querySupplier.get()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch! Seems there is no test, good time to add one.

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides Marios' comment - and maybe apart from a missing test, if feasible - it LGTM. Good spotting on unused/-sable formats.

if (field instanceof StDistance && q instanceof GeoDistanceQuery) {
return ExpressionTranslator.wrapIfNested(q, ((StDistance) field).left());
public Query wrapFunctionQuery(ScalarFunction sf, Expression field, Supplier<Query> querySupplier) {
if (field instanceof StDistance && querySupplier instanceof GeoDistanceQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no test for it?

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. However this PR needs to be broken into two - it's a bit more tedious but cleaner.
It looks to me there's a PR for removing date format and another one for adding lazy translation.
The latter in particular has subtle implications and as others have pointed out, it looks like we don't have complete testing in that area - hence the breakage.

@palesz
Copy link
Contributor Author

palesz commented Feb 10, 2021

Good catch. However this PR needs to be broken into two - it's a bit more tedious but cleaner.
It looks to me there's a PR for removing date format and another one for adding lazy translation.
The latter in particular has subtle implications and as others have pointed out, it looks like we don't have complete testing in that area - hence the breakage.

Makes sense, will break it down into two PRs.

@palesz palesz changed the title QL: Remove DateTimeFunction.dateTimeFormat() and turn eager query translations lazy QL: Remove the unnecessary DateTimeFunction.dateTimeFormat() Feb 10, 2021
@palesz
Copy link
Contributor Author

palesz commented Feb 10, 2021

Removed the introduction of lazyness from this PR, will resubmit once this PR is merged to avoid the conflicts.

@palesz palesz requested review from costin, matriv and bpintea February 10, 2021 23:01
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@palesz palesz merged commit 9ae5753 into elastic:master Feb 17, 2021
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Feb 17, 2021
…ic#68788)

Removes the `DateTimeFunction.dateTimeFormat()` and the 
`TranslatorHandler.dateTimeFormat()` methods that were
called, but had no effect on the translated queries.

One of the examples, when this happens, is when one side of the
`BinaryComparison` is a function. The `BinaryComparison` at the
end turns into a `ScriptQuery`, but in the intermediate steps the
`ExpressionTranslators` try to translate it to a `RangeQuery`.

Follows elastic#68783
@palesz palesz deleted the translator-cleanup branch February 17, 2021 14:08
palesz pushed a commit that referenced this pull request Feb 18, 2021
… (#69123)

Removes the `DateTimeFunction.dateTimeFormat()` and the 
`TranslatorHandler.dateTimeFormat()` methods that were
called, but had no effect on the translated queries.

One of the examples, when this happens, is when one side of the
`BinaryComparison` is a function. The `BinaryComparison` at the
end turns into a `ScriptQuery`, but in the intermediate steps the
`ExpressionTranslators` try to translate it to a `RangeQuery`.

Follows #68783
palesz pushed a commit that referenced this pull request Mar 2, 2021
Before the `ExpressionTranslators` did some unnecessary
`Expression` -> `Query` translations, where the result queries were thrown
away by later translations (by the `wrapFunctionQuery`).

This change adds laziness, so translations don't execute unnecessarily.

Follows #68783 and #68788
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Mar 2, 2021
Before the `ExpressionTranslators` did some unnecessary
`Expression` -> `Query` translations, where the result queries were thrown
away by later translations (by the `wrapFunctionQuery`).

This change adds laziness, so translations don't execute unnecessarily.

Follows elastic#68783 and elastic#68788
palesz pushed a commit that referenced this pull request Mar 2, 2021
Before the `ExpressionTranslators` did some unnecessary
`Expression` -> `Query` translations, where the result queries were thrown
away by later translations (by the `wrapFunctionQuery`).

This change adds laziness, so translations don't execute unnecessarily.

Follows #68783 and #68788
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants